package dao;

import java.sql.Connection;
import java.sql.SQLException;

import java.sql.PreparedStatement;

import cn.edu.tyu.util.DbUtil;
import domain.Users;

public class UserDaoImpl {
	public static int addUser(Users users) {
		
		Connection conn = DbUtil.getConnection();
		
		String sql = "insert into users values(?,?,?)";
		
		PreparedStatement ps = null;
		try {
			ps = conn.prepareStatement(sql);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		try {
			ps.setString(1,users.getUserid());
		} catch (SQLException e) {
			e.printStackTrace();
		}
		try {
			ps.setString(2,users.getUsername());
		} catch (SQLException e) {
			e.printStackTrace();
		}
		try {
			ps.setString(3,users.getUserpsw());
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		int res = 0;
		try {
			res = ps.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		DbUtil.backConn(conn, ps, null);
		return res;
	}
	
	public static void main(String[] args)  {
		UserDaoImpl userDao = new UserDaoImpl();
		Users users = new Users();
		users.setUserid("1");
		users.setUsername("zs");
		users.setUserpsw("123456");
		int res =userDao.addUser(users);
		System.out.println("res="+res);
		}
}

